students = []

while True:
    name = input('姓名：').strip()

    if name == '###':
        break
    
    while True:
        sex = input("性别：").strip()
        if sex in {'男', '女'}:
            break
        print('输入错误')

    while True:
        age = input("年龄：")
        try:
            age = int(age)
            break
        except:
            print("错误的年龄")
    
    while True:
        score = input("分数：")
        try:
            score = float(score)
            break
        except:
            print("错误的分数")
    
    stu = [name, sex, age, score]
    # stu = {'name':name, 'sex':sex, 'age':age, 'score':score}
    students.append(stu)
    print('成功录入该生信息')
    print('输入 ### 以结束')


def avg_of(students, category):
    total = 0
    num = 0
    for stu in students:
        if stu[1] in category:
            total += stu[3]
            num += 1
    return total/num


print(avg_of(students, {"男"}))
print(avg_of(students, {"女"}))
print(avg_of(students, {"男","女"}))
